package com.woniu.market_stall_web.controller;

import com.alibaba.fastjson.JSON;
import com.woniu.market_stall_web.entity.User;
import com.woniu.market_stall_web.service.AuctionRoomService;
import com.woniu.market_stall_web.service.AuctionStallService;
import com.woniu.market_stall_web.vo.AuctionRoomVo;
import com.woniu.market_stall_web.vo.AuctionStallVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.spring.web.json.Json;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("auctionStall")
public class AuctionStallController {

    @Autowired
    AuctionStallService auctionStallService;

    @Autowired
    AuctionRoomService auctionRoomService;


    @RequestMapping("/auctioning")
    public String auctioning(Map map , @RequestParam(value = "stallId") int stallId , HttpServletRequest request){
        User userInfo = (User) request.getSession().getAttribute("userInfo");
        String user = userInfo.getUsername();
        System.out.println(stallId);
        List<AuctionStallVo> auctionStallVos = auctionStallService.selectAuctioningOneStall(stallId);

        for (AuctionStallVo auctionStallVo : auctionStallVos) {
            System.out.println(auctionStallVo.getStallName());
        }
        map.put("auctionStallList", auctionStallVos);
        map.put("user", user);
        System.out.println("username=="+user);

        System.out.println("stallId=="+stallId);
        map.put("stallId", stallId);
        List<AuctionRoomVo> auctionRoomVos = auctionRoomService.queryRoomByStallId(stallId , user);
        map.put("auctionRoomList", auctionRoomVos);

//        auctionRoomService.signUpByUsername(stallId , user);
        return "bidding";
    }






}
